'use strict'
const Player = require('../component/player')
const BasicInfo = require('../component/basicInfo')
const playerDao = require('../dao/playerDao')

class PlayerHandle {
    constructor() {}

    create(uId, name, cb) {
        let basicInfo = new BasicInfo({
            name: name
        })
        let player = new Player({
            basicInfo: basicInfo
        })
        player = new Player(player)
        playerDao.newAndSave(uId, player, function (err, res) {
            cb(player)
        })
    }

    getPlayer(query, cb) {
        playerDao.getPlayerByQuery(query, function (err, res) {
            cb(err, res)
        })
    }

    getPlayers(uId, cb) {
        let query = {
            uId: uId
        }
        playerDao.getPlayersByQuery(query, function (err, res) {
            cb(err, res)
        })
    }

    initPlayer(data) {
        let player = new Player(data)
        player.initPlayer()
        return player
    }

}

let playerHandle = new PlayerHandle()

module.exports = playerHandle